package com.cyam.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cyam.domain.User;
import com.cyam.service.UserService;

@Controller
@RequestMapping("/user")
public class UserController {
	
	@Resource
	private UserService userService;

	@RequestMapping("/find")
	public String getUser(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<>();
		map.put("username", "张三");
		User user = userService.selectOne(map);
		request.setAttribute("pwd", user.getPassword());
		System.out.println(user.getId() + "********" + user.getPassword());
		return "user";
	}
	
	@RequestMapping("/json")
	@ResponseBody
	public User getUserJson(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<>();
		map.put("username", "张三");
		User user = userService.selectOne(map);
		request.setAttribute("pwd", user.getPassword());
		System.out.println(user.getId() + "********" + user.getPassword());
		return user;
	}
	
	@RequestMapping("/test/{viewname}")
	public String test(@PathVariable("viewname") String viewname,HttpServletRequest request){
		request.setAttribute("name", "hello");
		return viewname;
	}
	
	
}
